#! /usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) Huoty, All rights reserved
# Author: Huoty <sudohuoty@163.com>
# CreateTime: 2020-04-28 13:44:37

import socket


def is_net_ok(server=None):
    server = server or ("baidu.com", 80)
    sock = socket.socket()
    sock.settimeout(6)
    try:
        status = sock.connect_ex(server)
        if status == 0:
            sock.close()
            return True
        else:
            return False
    except Exception as e:
        print("Error:", e)
        return False


if __name__ == "__main__":
    print(is_net_ok())
    print(is_net_ok(server=("konghy.cn", 80)))
    print(is_net_ok(server=("google.com", 80)))
